import  os 
import cv2 as cv 
import numpy as np 


def draw_rect(img, boxes, col=(0, 255, 0)):
    boxes[:, 0] = np.maximum(boxes[:, 0], 0)
    boxes[:, 1] = np.maximum(boxes[:, 1], 0)
    boxes[:, 2] = np.minimum(boxes[:, 2], img.shape[1] - 1)
    boxes[:, 3] = np.minimum(boxes[:, 3], img.shape[0] - 1)

    for box in boxes.astype("int"):
        x_min, y_min, x_max, y_max  = box
        cv.rectangle(img, (x_min, y_min), (x_max, y_max), col)

if __name__ == "__main__":
    box = np.load("./box_true.npy")[:,:4]
    prio = np.load("./prio.npy")
    img = (np.load("./img.npy") * 128.0 + 128).astype("uint8")


    h, w, c = img.shape

    box[:, 0::2] *= w 
    box[:, 1::2] *= h 
    # box[:, 2:] += box[:, :2]
    draw_rect(img, box)

    prio[:, 0::2] *= w 
    prio[:, 1::2] *= h 
    # prio[:, 2:] += prio[:, :2]
    draw_rect(img, prio, (255, 0, 0))

    cv.imshow("img", img)
    cv.waitKey(0)



    


